from pymongo import MongoClient
from config.db_config import mongo_ip,mongo_port,user_name,password
MONGO_URL = 'mongodb://{}:{}@{}:{}/?authSource=admin'.format(user_name,password,mongo_ip,mongo_port)
# MONGO_URL = 'mongodb://{}:{}'.format(mongo_ip,mongo_port)
class ConnMongo(object):
    def __new__(self):
        if not hasattr(self, 'instance'):
            self.instance = super(ConnMongo, self).__new__(self)
            self.instance.conn = MongoClient(MONGO_URL)
        return self.instance

def conn_db(collection, db_name):
    conn = ConnMongo().conn
    return conn[db_name][collection]

if __name__ == '__main__':
    my_collection = conn_db(collection='pa_info', db_name='hetai')
    my_collection.insert_one({'name':'人员1','is_mask':1,'code_states':0,'temp':36.1})
